package com.room.search.service;

import com.room.search.domain.RoomGoodSearch;
import com.room.search.repository.RoomGoodSearchRepository;
import com.room.search.service.dto.RoomGoodSearchDTO;
import com.room.search.service.mapper.RoomGoodSearchMapper;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Service Implementation for managing {@link RoomGoodSearch}.
 */
@Service
@Transactional
public class RoomGoodSearchService {

    private final Logger log = LoggerFactory.getLogger(RoomGoodSearchService.class);

    private final RoomGoodSearchRepository roomGoodSearchRepository;

    private final RoomGoodSearchMapper roomGoodSearchMapper;

    public RoomGoodSearchService(RoomGoodSearchRepository roomGoodSearchRepository, RoomGoodSearchMapper roomGoodSearchMapper) {
        this.roomGoodSearchRepository = roomGoodSearchRepository;
        this.roomGoodSearchMapper = roomGoodSearchMapper;
    }

    /**
     * Save a roomGoodSearch.
     *
     * @param roomGoodSearchDTO the entity to save.
     * @return the persisted entity.
     */
    public RoomGoodSearchDTO save(RoomGoodSearchDTO roomGoodSearchDTO) {
        log.debug("Request to save RoomGoodSearch : {}", roomGoodSearchDTO);
        RoomGoodSearch roomGoodSearch = roomGoodSearchMapper.toEntity(roomGoodSearchDTO);
        roomGoodSearch = roomGoodSearchRepository.save(roomGoodSearch);
        return roomGoodSearchMapper.toDto(roomGoodSearch);
    }

    /**
     * Partially update a roomGoodSearch.
     *
     * @param roomGoodSearchDTO the entity to update partially.
     * @return the persisted entity.
     */
    public Optional<RoomGoodSearchDTO> partialUpdate(RoomGoodSearchDTO roomGoodSearchDTO) {
        log.debug("Request to partially update RoomGoodSearch : {}", roomGoodSearchDTO);

        return roomGoodSearchRepository
            .findById(roomGoodSearchDTO.getId())
            .map(existingRoomGoodSearch -> {
                roomGoodSearchMapper.partialUpdate(existingRoomGoodSearch, roomGoodSearchDTO);

                return existingRoomGoodSearch;
            })
            .map(roomGoodSearchRepository::save)
            .map(roomGoodSearchMapper::toDto);
    }

    /**
     * Get all the roomGoodSearches.
     *
     * @return the list of entities.
     */
    @Transactional(readOnly = true)
    public List<RoomGoodSearchDTO> findAll() {
        log.debug("Request to get all RoomGoodSearches");
        return roomGoodSearchRepository
            .findAll()
            .stream()
            .map(roomGoodSearchMapper::toDto)
            .collect(Collectors.toCollection(LinkedList::new));
    }

    /**
     * Get one roomGoodSearch by id.
     *
     * @param id the id of the entity.
     * @return the entity.
     */
    @Transactional(readOnly = true)
    public Optional<RoomGoodSearchDTO> findOne(Long id) {
        log.debug("Request to get RoomGoodSearch : {}", id);
        return roomGoodSearchRepository.findById(id).map(roomGoodSearchMapper::toDto);
    }

    /**
     * Delete the roomGoodSearch by id.
     *
     * @param id the id of the entity.
     */
    public void delete(Long id) {
        log.debug("Request to delete RoomGoodSearch : {}", id);
        roomGoodSearchRepository.deleteById(id);
    }
}
